#ifndef _CHANNELMANAGER_H_
#define _CHANNELMANAGER_H_

#include "Channel.h"
#include "GameRoom.h"
#include <utillib/stl/map.h>
#include <utillib/stl/queueList.h>
#include <utillib/util/singleton.h>

class ChannelManager : public utillib::stl::MapWithInteger < GameRoom * >
{
private:
	struct SendGameRoomInfo : public std::binary_function < GameRoom *, Character * , bool >
	{ 
		bool operator()( GameRoom *gameRoom, Character *character ) const 
		{
			if ( gameRoom )
			{
				SYNC_GET_PACKET( channelInfoPacket );
				gameRoom->makeAddChannelAck( channelInfoPacket );
				character->send( channelInfoPacket );
			}

			return ( true );
		} 
	};
public:
	ChannelManager();
	virtual ~ChannelManager();

	void initialize();

	SingletonInstance( ChannelManager );

	DWORD enter( short int roomNumber, Character *character );
	DWORD enterLobby( Character *character );
	DWORD leave( Character *character, Channel *channel = NULL );
	DWORD leaveLobby( Character *character );

	DWORD create( char *name, Character *character );

	void sendGameRoomList( Character *character );
	Channel *getLobby();
private:

	Channel m_lobbyChannel;
	utillib::stl::QueueList < GameRoom * > m_channelPool;
};
#endif